def find_set(x):
    if x != s[x]:
        s[x] = find_set(s[x])
    return s[x]

def merge_set(x, y):
    x, y = find_set(x), find_set(y)
    if x != y:
        s[x] = s[y]

n = int(input())
s = list(range(n + 1))
for i in range(1, n + 1):
    merge_set(i, int(input()))

for i in range(1, n + 1):
    s[i] = find_set(i)
print(len(set(s)) - 1)